<?php
/**
 * 添加产品产品信息
 * 2013年4月19日10:09:06
 * cgp
 */
$type=array('A','B','C','F','G','H');
if(!in_array($_GET['type'],$type) && $_GET['type']) exit('非法访问');
if(in_array($_GET['type'],array('A','B','C')) && $_GET['a']==1){
    echo <<<HTML
        <script>
        window.location.href="pft_resource.html?m=rep&type={$_GET['type']}"
        </script>
HTML;
}
use \pft\Prod\Product;
include 'common/header.html';
include 'common/left.html';
include 'common/autoload.php';
include 'common/Prod_Common.php';
if($access['yd']){
    include 'common/prodField_yd.php';
}else{
    include 'common/prodField.php';
}

$ptype = strtoupper($_GET['type']);
$sid = abs($_GET['sid']);//景区ID
$uploadUrl = 'call/uploadThumbImage.php';
$saveBtn = '<button class="ui-button ui-button-lblue" id="saveProduct" data-wrap="ticketBox" type="button">保存，下一步</button>';
$apply_did = $_SESSION['dtype']==6? $_SESSION['sid'] : $_SESSION['memberID'];
if($_SESSION['sdtype']!=9){
    if($_SESSION['dtype']==6 ) {
        if(\pft\Member\MemberAccount::GetMemType($_SESSION['sid'])!=0) {
            exit('<script>alert("您的上级不是供应商身份，无法发布产品。")</script>');
        }
    }
    elseif($_SESSION['dtype']!=0) {
        exit('<script>alert("您不是供应商身份，无法发布产品。")</script>');
    }
    if($sid){
        $sel_apply_did = "select apply_did from uu_land where id=$sid limit 1";
        $le->query($sel_apply_did);
        $row = $le->fetch_assoc();
        if($row['apply_did']!=$apply_did )
            exit('<script>alert("这不是你的产品")</script>');
        }
}elseif( !strpos($_SESSION['qx'],'upProd') && $_SESSION['memberID']!=1){
        exit('<script>alert("您无权访问这个页面")</script>');
}
//print_r($GLOBALS['le']);
$obj = new Product($GLOBALS['le']);
$page_title = '产品发布';
$topicList = array();//产品主题
//echo $_GET['sid'];
if(isset($_GET['sid']) && abs($_GET['sid']>0)) {
    $page_title = '产品编辑';
    $isedit = empty($_GET['step'])? true : false ;
    $product_id = abs($_GET['sid']);
    if ($_SESSION['sdtype']==9 ) {
        $jdata = $obj->GetProductById($product_id);
    }
    elseif($_SESSION['dtype']==2) {
        $sql = "SELECT account FROM pft_member WHERE id={$_SESSION['memberID']} LIMIT 1";
        $GLOBALS['le']->query($sql);
        $GLOBALS['le']->fetch_assoc();
        $salerid = $GLOBALS['le']->f('account');
        $jdata = $obj->GetProductById($product_id, 0, $salerid);
    }
    elseif ($_SESSION['dtype']==0 || $_SESSION['dtype']==6 ) {
        $jdata = $obj->GetProductById($product_id, $_SESSION['sid']);
    }
    // $jdata = $obj->GetProductById($product_id);
    if (!$jdata ) {
        exit('产品不存在');
    }
    if(in_array($jdata['p_type'],array('A','B','C')) && $_GET['a']==1){
        echo <<<HTML
        <script>
        window.location.href="pft_resource.html?m=rep&sid={$_GET['sid']}"
        </script>
HTML;

    }

    $apply_did = $jdata['apply_did'];
    $ptype = $jdata['p_type'];
    $topicList = explode(',', $jdata['topic']);
    $endtopic = end($topicList);
    //echo $ptype;
    if($jdata['attribute']) {
        //echo $jdata['attribute'];
        $package_data = $obj->PackageDataFormat($jdata['attribute']);
        $input_pack = "<input type='hidden' value='{$jdata['attribute']}' name='package_attr' id='package_attr'/>";
    }
    $saveBtn = '<button class="ui-button ui-button-lblue" id="saveProduct" type="button">保存</button>';
}
//TODO::同步产品禁止修改
if ($jdata['sync_status']==2)  $saveBtn = '同步产品禁止修改';


// 多图片处理
if($access['yd']){
    $imgUrl = !empty($jdata['imgpathGrp']) ? $jdata['imgpathGrp'] :'images/defaultThum.jpg';
    if(!empty($jdata['imgpathGrp'])) $imgUrl = unserialize($jdata['imgpathGrp']);
    for($i=0;$i<4;$i++){
        $imgArr[$i]= (is_array($imgUrl)&&$imgUrl[$i]) ? $imgUrl[$i]:'images/defaultThum.jpg';
    }
}else{
    $imgUrl = !empty($jdata['imgpath']) ? $jdata['imgpath'] :'images/defaultThum.jpg';
}


$package_str_tpl = '<li><p>产品名:{}</p></li>';
if($ptype == 'F' && !empty($_POST['package_data'])) {
    $attribute = urldecode($_POST['package_data']);
    $package_data = $obj->PackageDataFormat($attribute);
    $input_pack = "<input type='hidden' value='{$attribute}' name='package_attr' id='package_attr'/>";
}
$page_title = "产品发布 - ";


// 页面变量放置
// $posi = explode('|', $jdata['lng_lat_pos']);
// $posi_c = count($posi);
// if($posi_c==0){
	// $posi[0] = '0,0'; $posi[1] = '0,0';
// }elseif($posi_c==1){
	// $posi[0] = '0,0';
// }
// $var['start_place_tude'] = $posi[0];// 开始经纬度
// $var['end_place_tude'] = $posi[1];// 结束经纬度
// if ($_GET['cgp']) {
    // print_r($jdata);
	// print_r($var);
// }
// if($_SESSION['sid']==1433){
	// echo $jdata['bhjq'];
	// echo $package_content;
	// exit;
// }
if($ptype=='H'){// 演出类产品场馆选择数据
	include_once '/var/www/html/new/d/module/common/Db.class.php';
	$dbConf = include '/var/www/html/new/d/module/common/db.conf.php';// 远端服务器配置信息
	\PFT\Db::Conf($dbConf['remote_1']);
	$sql = "select id as venue_id,venue_name from pft_venues where apply_did=? and status=?";
	$stmt= \PFT\Db::Connect()->prepare($sql);
	$stmt->execute(array($_SESSION['sid'], 0));
	$venues = array();
	while($row=$stmt->fetch(\PDO::FETCH_ASSOC)) $venues[] = $row;
	// print_r($venues);
}
$var['end_place_tude'] = $jdata['lng_lat_pos'] ? $jdata['lng_lat_pos']:'0,0';

include TPLPATH.'product_body.html';
include('common/footer.html')?>